วันเสาร์ที่ 10 พฤศจิกายน พ.ศ. 2561

Backup ข้อมูล

      เนื่องจากโน๊ตบุคมีปัญหาและจะทำการลงระบบปฏิบัติการใหม่ พร้อมทั้งลงโปรแกรมใหม่ทั้งหมดทำให้ต้องทำการสำรองข้อมูลไว้ก่อนล่วงหน้า

วันศุกร์ที่ 9 พฤศจิกายน พ.ศ. 2561

mini Project [ออกแบบGUI]

         ได้ออกแบบหน้าต่าง GUI สำหรับหน้าการใช้งานโปรแกรมตาม use case ต่างๆ ดังนี้

use case 1 : การค้นหาความหมาย

ภาพแรก : หน้าต่างโปรแกรมเริ่มต้น ช่องด้านบนสุดสำหรับใส่คำศัพท์ที่ต้องการค้นหา
                 ปุ่ม search กดเพื่อแปลความหมาย
ภาพสอง : เมื่อใส่คำศัพท์ลงไป และ กด search แล้ว
                 ถ้าคำศัพท์นั้นมีอยู่ในคลังข้อมูล และ สะกดถูกต้อง จะแปลความหมาย และแสดงคำเหมือน
ภาพสาม : ถ้าคำศัพท์นั้นสะกดไม่ถูกต้องหรือไม่มีอยู่ในคลังข้อมูล จะแสดงคำว่า Word not found


use case 2 : เก็บคำศัพท์ลง KEEP

หลังจากค้นหาคำศัพท์นั้นเจอและต้องการเก็บคำศํพท์ไว้ ให้กดที่รูปดาวที่มุมด้านขวาล่าง คำศัพท์นั้นก็จะไปปรากฏในรายการคำศัพท์หน้า keep

ภาพแรก : เมื่อเข้าไปที่หน้า keep จะเห็นรายการคำศัพท์ที่เราติดดาวไว้
ภาพสอง : หากกดเข้าไปที่คำศัพท์ใด จะเข้าไปสู้หน้าแปลความหมายของคำศัพท์นั้น
                 หากกดที่ดาวอีกครั้ง จะเป็นการยกเลิกการ keep
ภาพสาม : คำศัพท์ที่ถูกยกเลิกการ keep จะหายไปจากหน้ารายการคำศัพท์ที่ keep

use case 3 : เกม SPELL

 
รูปแบบหน้าจอจะมีความหมายภาษาไทยอยู่ด้านบน และให้ใส่ตัวพยัญชนะตามความหมายของคำนั้นๆ

 แสดง ความหมายและ __ ตามจำนวนพยัญชนะของคำศัพท์
หากใส่ความหมายถูกต้อง จะเปลียนไปคำถัดไป

           
 หากใส่ผิด จะทำการเคลียร์ค่าออกทั้งหมด ให้ผู้เล่นสะกดคำใหม่ และถ้าสะกดผิดครบ 3 ครั้ง จะเก็บคำนั้นลงในหมวด keep และเปลี่ยนคำศัพท์ในการเล่นการสะกด


วันอังคารที่ 6 พฤศจิกายน พ.ศ. 2561

mini Project

           นำเสนอโปรแกรมเพื่อการเรียนรู้ภาษาอังกฤษ ชื่อ Grade A English โดยรายละเอียดมีดังนี้

แผนการดำเนินงาน
- ออกแบบหน้าต่างโปรแกรม

- สร้างหน้าต่าง GUI
- ทำฟังก์ชันต่าง ๆ ของโปรแกรม
   - ค้นหาความหมาย
   - ดูคำที่ชื่นชอบ
   - ฝึกสะกดคำ
- ทดสอบการใช้งาน
- ปรับปรุง

User  ภายในโปรแกรมเป็นการใช้งานแบบ 1 ผู้ใช้ มีการทำงานภายในแบ่งออกเป็น 3 ส่วน คือ

         1.ค้นหาและแปลความหมาย
           2.เพิ่มคำที่ชื่นชอบ
           3.เล่นเกมสะกดคำ
ขั้นตอนการทำงานของแต่ละ case :         
            1.ค้นหาและแปลความหมาย
- พิมพ์คำศัพท์ภาษาอังกฤษลงไปในช่องค้นหา
- กดค้นหา
- ถ้าสะกดถูก/มีอยู่ในคลังข้อมูล ให้ แสดงความหมายของคำศัพท์ และ คำที่มีความหมายเหมือนกัน
- ถ้าสะกดไม่ถูกต้อง หรือ ไม่มีอยู่ในคลังคำศัพท์ ให้แสดง “ Word not found “
            2. เพิ่มคำที่ชื่นชอบ
- ตอนแปลความหมาย ให้กด ปุ่มเพื่อเพิ่มลงในคำที่ชื่นชอบ
- กดที่คำศัพท์นั้นแล้วจะแสดงความหมาย
- ถ้ากดปุ่มชอบอีกครั้งจะเป็นการยกเลิก แล้วนำคำศัพท์ออกจากคำที่ชื่นชอบ
            3. เล่นเกมสะกดคำ
- เมื่อกดเข้ามาจะแสดงหน้าให้เล่นเกมเลย
- สุ่มคำศัพท์มาจากคลังข้อมูล
- แสดงความหมายหรือภาพสัญลักษณ์ที่แสดงถึงคำศัพท์
- สร้าง _ ตามจำนวนตัวอักษร
- ให้ผู้ใช้ใส่ตัวอักษรภาษาอังกฤษให้ถูกต้องตรงตามความหมายในภาษาไทย
- ถ้าใส่ถูกต้อง ให้สุ่มคำใหม่ขึ้นมาและทำเหมือนเดิม
- ถ้าใส่ผิด 3 ครั้ง ให้เก็บคำนั้นใส่ในคำที่ชื่นชอบแล้วก็เปลี่ยนไปคำถัดไป
- ถ้าจะเลิกเล่นให้กดออก แล้วจะกลับไปหน้าหลัก


วันอาทิตย์ที่ 4 พฤศจิกายน พ.ศ. 2561

Cat & Rat [ java update ]

แก้ไข
- ย้าย check catch ไปใส่เป็น method ใน class board
- แก้ไขชื่อตัวแปรที่ไม่สื่อความหมาย
- ทำให้หนูเดินได้

=======class Board=========
         ย้ายเงื่อนไขการตรวจสอบการชนกันมาใส่ใน class board
public class Board {
int row;
int col;
private char board[][];
char player = 'C';
int score = 0;
    public Board (int row,int col) { 
    this.row = row;
    this.col = col;
    this.board= new char[this.row][this.col];
   
  }
    
    
    public char getBoard(int row,int col) {
   
    return this.board[row][col];   
   
    }
    
    public void setBoard(char C_or_R,int row,int col) {
    if(player == C_or_R) this.board= new char[this.row][this.col];
    this.board[row][col] = C_or_R ; 
   
    }
    
    public boolean check(int ratrow, int ratcol, int catrow , int catcol) {
if(catrow == ratrow && catcol == ratcol) {
score++;
return true;
}else return false;
}
}

========class Display============
            เรียกคะแนนจาก class board มาแสดง
public class Display {
private Board board;
public Display(Board board) {
this.board = board;
}
    
       public void display() {
// create and show board
        for (int i = 0; i < this.board.row; i++) {
            for (int j = 0; j < this.board.col; j++) {
                System.out.print(this.board.getBoard(i,j)+"|");
                }
            System.out.println();            
            }
        System.out.println("Score : "+this.board.score);
}
  
}

===========class Cat และ class Input ไม่มีการเปลี่ยนแปลง================

========class Rat==========

import java.util.*; 
public class Rat {
private Board board;
private Cat cat;
private boolean run_random;
int ratrow = 2;
int ratcol = 2;
int ratran=1;
int ratbf = 0;
public Rat(Board board , Cat cat){
this.board = board;
this.cat = cat;
}
public void spawn() {
this.board.setBoard('R' , ratrow, ratcol);
}
public void randomRat(){
run_random = true;
            Random ran_r = new Random(); 
            Random ran_c = new Random();
   
    if(run_random == true && this.board.check(ratrow, ratcol, this.cat.row, this.cat.col) == false)this.board.setBoard('R',ratrow,ratcol);
      while(run_random) {
                                //เปลี่ยนวิธีหาหนู ไม่วน loop แล้ว
    if(this.board.getBoard(ratrow, ratcol) == 'R') {
    run_random = false;
            }
                                 else if ((this.board.row+1)*(this.board.col+1) == this.board.row*this.board.col && run_random == true) { 
    ratrow = ran_r.nextInt(this.board.row); 
    ratcol = ran_c.nextInt(this.board.col);
    this.board.setBoard('R',ratrow,ratcol);
            }
    }
   
        }
//เงื่อนไขให้หนูเดินทีละช่อง
        public void ratrun() {
Random ranmove = new Random();
ratran = ranmove.nextInt(4); 
if(ratran == 0 && ratrow >0) {
ratbf = ratrow;
ratrow -= 1;
this.board.setBoard(' ',ratbf,ratcol);
this.board.setBoard('R',ratrow,ratcol);
System.out.println("up");
}
else if(ratran == 1 && ratrow < this.board.row-1) {
ratbf = ratrow;
ratrow += 1;
this.board.setBoard(' ',ratbf,ratcol);
this.board.setBoard('R',ratrow,ratcol);
System.out.println("down");
}
else if(ratran == 2 && ratcol > 0) {
ratbf = ratcol;
ratcol -= 1;
this.board.setBoard(' ',ratrow,ratbf);
this.board.setBoard('R',ratrow,ratcol);
System.out.println("left");
}
else if(ratran == 3 && ratcol < this.board.col-1) {
ratbf = ratcol;
ratcol += 1;
this.board.setBoard(' ',ratrow,ratbf);
this.board.setBoard('R',ratrow,ratcol);
System.out.println("right");
}
else ratrun();
    }
}

        
======================================================

วันเสาร์ที่ 3 พฤศจิกายน พ.ศ. 2561

CAT & RAT [java Update]

Commit : https://bitbucket.org/Wanvipa/catandrat/commits/91b214fe8f3f873390bd73d385484f50402240f6


=====class board=====
          แก้ไขฟังก์ชัน setBoard ให้นำค่า C มาใส่ลงใน ตำแหน่งและอัพเดทบอร์ดใหม่
public class Board {
int row;
int col;
private char board[][];
char player = 'C';

         public Board (int row,int col) {
             this.row = row;
              this.col = col;
              this.board= new char[this.row][this.col];
  }
   
        public char getBoard(int row,int col) {
              return this.board[row][col];       
             }

        public void setBoard(char C_or_R,int row,int col) {
              if(player == C_or_R) this.board= new char[this.row][this.col];
              this.board[row][col] = C_or_R ;   
                 }
    }

=====class display=====
            เพิ่มส่วนการแสดงคะแนน

public class Display {
private Board board;
private CheckCatch check_catch;

public Display(Board board , CheckCatch check_catch) {
this.board = board;
this.check_catch = check_catch;
}
   
    public void display() {
// show board
    for (int i = 0; i < this.board.row; i++) {
for (int j = 0; j < this.board.col; j++) {
                           System.out.print(this.board.getBoard(i,j)+"|");
                         }
                   System.out.println();           
                 }
                 //print score
                 System.out.println("Score : "+this.check_catch.score);
}

}

=====class Cat=====
            เก็บตำแหน่งของแมว และ รับ row และ column มาใส่ใน move เพื่อให้แมวเกิดการเคลื่อนที่

public class Cat {
private Board board;
int row = 0;
int col = 0;

public Cat(Board board) {
this.board = board;
    }

public void pos() {
this.board.setBoard(this.board.player, row, col);
    }
public void move(int row , int col) {
this.board.setBoard(this.board.player,row,col);
    }
}

=====class Input=====
            รับค่า ตัวเลข 2 4 6 และ 8 มากำหนดทิศทางการเดินของแมว โดย
2 คือ เดินลง
4 คือ เดินไปทางซ้าย
6 คือ เดินไปทางขวา
8 คือ เดินขึ้น

แล้วส่งค่าไปเปลี่ยน row และ column ของ Cat

import java.util.Scanner;
public class InputPOS {
private Board board;
private Cat cat;

public InputPOS(Board board, Cat cat) {
this.board = board;
this.cat = cat;
}

public void key() {
Scanner inPlayer = new Scanner(System.in);
System.out.print( "Turn "+this.board.player + " move : ");
int move = inPlayer.nextInt();
System.out.println();

if(move == 8)this.cat.row -= 1;
else if(move == 2)this.cat.row += 1;
else if(move == 4)this.cat.col -= 1;
else if(move == 6)this.cat.col += 1;
this.cat.move(this.cat.row,this.cat.col);
}
}

=====class Rat=====
           กำหนดให้หนูเกิดมาที่ตำแหน่ง row=2,column=2
           ถ้ามีหนูอยู่ในตารางแล้วไม่ต้องสร้างหนูตัวใหม่
           ถ้าในตารางไม่มีหนูอยู่ ให้สุ่มหนูมาเกิด ณ ตำแหน่งใดๆ ในบอร์ด

import java.util.*; 
public class Rat {
private Board board;
private boolean run_random;
private CheckCatch check_catch;
int nxtr = 2;
int nxtc = 2;

public Rat(Board board, CheckCatch check_catch){
this.board = board;
this.check_catch = check_catch;
       }
        //ตำแหน่งเกิด
public void pos() {
this.board.setBoard('R' , nxtr, nxtc);
        }

public void randomRat(){
run_random = true;
    Random ran_r = new Random(); 
    Random ran_c = new Random();
    
        if(run_random == true && this.check_catch.check(nxtr, nxtc) == false)
this.board.setBoard('R',nxtr,nxtc);    
while(run_random) {
            for(int i = 0 ; i < this.board.row ; i++) {
            for(int j = 0 ; j < this.board.col ; j++) {
           if(this.board.getBoard(i, j) == 'R') {
           run_random = false;
            }
//ถ้าไม่มีหนู ให้สุ่มตำแหน่ง row,column ใหม่ขึ้นมาให้หนู
else if ((i+1)*(j+1) == this.board.row*this.board.col && 
                                                 run_random == true) { 
            nxtr = ran_r.nextInt(this.board.row); 
            nxtc = ran_c.nextInt(this.board.col);
            this.board.setBoard('R',nxtr,nxtc);
    }
             }
    
 }
}        
 }
}

=====class check catch=====
            ตรวจสอบตำแหน่งแมวและหนู ถ้าตำแหน่งตรงกันให้บวกคะแนนเพิ่มและนำหนูออกจากบอร์ดให้เหลือไว้เพียงแมว

public class CheckCatch {
private Cat cat;
int score = 0;

public CheckCatch(Cat cat){
this.cat = cat;
}

public boolean check(int rat_row, int rat_col) {
if(this.cat.row == rat_row && this.cat.col == rat_col) {
score++;
return true;
}
else return false;
}
}

=====class Main=====
           เรียกใช้ class ต่างๆ

public class Main {
public static void main(String[] args) {
Board board = new Board(5,5);
Cat cat = new Cat(board);
InputPOS input = new InputPOS(board,cat);
CheckCatch check_catch = new CheckCatch(cat);
Display show = new Display(board,check_catch);
Rat rat = new Rat(board,check_catch);
cat.pos();
rat.pos();

while(true) {
show.display();
input.key();
rat.randomRat();

}
}
}

               ==================================================

แมวสามารเดินไปจับหนูและมีคะแนนขึ้นแล้ว แต่หนูยังเดินไม่ได้

วันอังคารที่ 30 ตุลาคม พ.ศ. 2561

CAT & RAT [java]

            ทำเกม แมวจับหนู ด้วยการเขียนภาษา java โดยการแบ่งออกเป็น class
รูปแบบของเกม
- สร้างตารางขนาด n ช่องขึ้นมา
- ให้หนูเดินอยู่ภายในตาราง
- ให้ผู้เล่นบังคับแมวด้วนแ้นตัวเลขเพื่อเดินไปจับหนู
- เมื่อจับหนูได้แล้ว คะแนนจะเพิ่มขึ้น 1 คะแนน ต่อหนู 1 ตัว
- จะสุ่มหนูมาเกิดที่ตำแหน่งใหม่ให้แมวได้จับต่อไป

====class board=====ทำการสร้างบอร์ด ส่งค่าบอร์ดออกไปและรับค่ามาใส่ลงบอร์ด

public class board {
  private int row;
  private int col;
  private char board[][];
  private char player = 'C';
   public board (int row,int col) {
      this.row = row;
      this.col = col;
      this.board= new char[this.row][this.col];
    }
   
   public char getBoard(int row,int col) {
       return this.board[row][col];   
    }
    public void setBoard(int row,int col,char player) {
      this.board[row][col] = player ;
    }

}

====class display===== 
ทำการแสดงบอร์ดออกมาในส่วนผลลัพธ์ของโปรแกรม

public class Display {
private floor board;
  public Display(Board board) {
  this.board = board;
  }
   
    public void display() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print("\t" + this.board.getBoard(i,j));
            }
            System.out.println();           
        }     
}  

====class MAIN====
เรียกใช้งาน class ต่าง ๆ

public class MAIN {
    public static void main(String[]args){
      Board board = new Board(3,3);
      Display show = new Display(board);
   
       while(true) {
           show.display();
           break;
           }
    }
}       

                                      ====================================
สร้างบอร์ดและแสดงบอร์ดได้แล้ว

วันจันทร์ที่ 29 ตุลาคม พ.ศ. 2561

update XO [JAVA]

ทำการแก้ไข นำ การ checkwin ไปใส่ไว้ใน class Board
แก้ไข นำตัวแปร ออกจาก Main
update to bitbucket  :  https://bitbucket.org/Wanvipa/tictactoe/src/default/

===========Class Board=============

public class Board {
private int row;
private int col;
private int x = 1;
private int draw = 0;
private char board[][];
private boolean game_run;
char player = 'X';


    public Board (int row,int col) {
    this.row = row;
    this.col = col;
    this.board= new char[this.row][this.col];
     
    }
 
 
    public char getBoard(int row,int col) {
    return this.board[row][col];   
   
    }
 
    public void setBoard(int row,int col) {
    this.board[row][col] = player ;
   
    }
    public char changeplayer() {
    if (player=='X') {
    return player = 'O';
}
    else {
    return player = 'X';
}
    }
 
public void check_win(int draw){

//check lick
int check_lick = 0;
int r = 2;
System.out.println();
for(int q = 0; q < 3; q++) {
if(this.board[q][q] == 'X')check_lick += 1;
if(this.board[q][q] == 'O')check_lick -= 1;
}
lick_win(check_lick);
check_lick = 0;
for(int p = 0; p < 3; p++) {
if(this.board[p][r] == 'X')check_lick += 1;
if(this.board[p][r--] == 'O')check_lick -= 1;

}
lick_win(check_lick);

//check row and column
for(int i = 0; i < 3; i++) {
int check_row = 0; 
int check_col = 0;
for(int j = 0; j < 3; j++) {
if(this.board[i][j] == 'X')check_row += 1;
if(this.board[i][j] == 'O')check_row -= 1;
if(this.board[i][j] == 'X')check_col += 1;
if(this.board[i][j] == 'O')check_col -= 1;

}

//print result
if(check_row == 3 || check_col == 3) {
System.out.println("X is winner");
x = 0; run_game();
}else if(check_row == -3 || check_col == -3) {
System.out.println("O is winner");
x = 0; run_game();
}else if(draw == 9) {
System.out.println("Draw both");
x = 0; run_game();
}
}
draw += 1;
}
public void lick_win(int check_lick) {
if(check_lick == 3) {
System.out.println("X is winner");
x = 0; run_game();
}
if(check_lick == -3) {
System.out.println("O is winner");
x = 0; run_game();
}

}

public boolean run_game() {
if(x==0)game_run = false;
else if(x==1)game_run = true;
return game_run;
}
}

 
===========Class Main=============
public class MAIN {

    public static void main(String[]args){
    Board board = new Board(3,3);
    Display show = new Display(board);
    InputXO input = new InputXO(board);
   
    while(board.run_game()) {
    show.display();
    input.Inputboard();
    board.changeplayer();
}
        }

}