Cov txheej txheem:

Chaw Sib Tw Ua Si Version 2: 5 Cov Kauj Ruam
Chaw Sib Tw Ua Si Version 2: 5 Cov Kauj Ruam

Video: Chaw Sib Tw Ua Si Version 2: 5 Cov Kauj Ruam

Video: Chaw Sib Tw Ua Si Version 2: 5 Cov Kauj Ruam
Video: Yasmi - Txiv Nraug Ntsuag ft. JN Vang (Music Video) 2024, Kaum ib hlis
Anonim
Image
Image

Hav sawv daws. Ua ntej qhov game game version, ı luam tawm thawj version ntawm game. Hnub no, ı yuav qhia koj qhov Chaw Sib Tw Sib Tw version 2. Cia saib cov kauj ruam…

Kauj ruam 1: PARTS

SCHEMA
SCHEMA

Nov yog cov npe ntawm ntu uas kuv tau siv los ua txoj haujlwm no:

  • Arduino UAS
  • Joystick Module
  • Jumper Wires (txiv neej rau txiv neej thiab txiv neej rau poj niam)
  • Cov qhob cij

Kauj ruam 2: SCHEMA

VCC -> Arduino 5V

BL -> Arduino tus pin 3

GND -> Arduino GND

CLK (SCLK) -> Arduino tus pin 8

DIN (MOSI) -> Arduino tus pin 9

DC -> Arduino tus pin 10

CE lossis CS -> Arduino tus pin 12

RST (RESET) -> Arduino tus pin 11

Kauj ruam 3: CODE

CODE
CODE

Txoj cai tau piav qhia txog kev ua haujlwm. Koj yuav nkag siab nws yooj yim. Yog tias koj muaj teeb meem, koj tuaj yeem tiv tauj kuv.

#suav nrog

LCD5110 lcd (8, 9, 10, 11, 12); // (clk, cin, dc,, rst, ce)

boolean kontrol = tseeb;

boolean dusmanoldu = tseeb;

sab nrauv uint8_t SmallFont ; // piav qhia cov fonts

sab nrauv uint8_t MediumNumbers ; sab nrauv uint8_t arac ; // piav qhia peb cov duab sab nrauv uint8_t dusmanAraci ; // desribe yeeb ncuab zoo const int xpin = A0; // joystick x pin char pozisyon = 3; // piav qhia qhov chaw nyob, peb cov duab pib qhov chaw 3 int BL = 3; int skor = 0; int hais = 0; koj dusmankonum1; // piav qhia tus yeeb ncuab1 x qhov chaw int dusmankonum2; // piav qhia tus yeeb ncuab2 x qhov chaw int dusmankonum3; // piav qhia tus yeeb ncuab3 x qhov chaw int dusmankonum4; // piav qhia tus yeeb ncuab4 x qhov chaw int dusmankonum5; // piav qhia tus yeeb ncuab5 x qhov chaw int dusmaninYdekonumu;

void oyunEkrani () {// teeb tsa game screen

lcd.clrScr (); lcd.drawRect (0, 0, 47, 47); // peb kos duab plaub lcd.setFont (SmallFont); // teeb tsa lcd.print ("skor", 57, 1); // luam tau qhab nia lcd.print ("hiz", 60, 24); // luam ceev lcd.setFont (MediumNumbers); // teeb tsa lcd.printNumI (sau, 55, 8); // tau qhab nia lcd.printNumI (hiz, 63, 32); // tau ceev lcd.update (); }

void dusmanAracidurum (int yer, int asama) {// teeb tsa qhov chaw rau cov yeeb ncuab duab

yog (yer == 1) {lcd.drawBitmap (2, asama, dusmanAraci, 7, 7); lcd.update ();} // yog qhov chaw = 1 kos tus yeeb ncuab lub chaw no yog (yer == 2) {lcd.drawBitmap (10, asama, dusmanAraci, 7, 7); lcd.update ();} yog (yer == 3) {lcd.drawBitmap (18, asama, dusmanAraci, 7, 7); lcd.update (); } yog (yer == 4) {lcd.drawBitmap (26, asama, dusmanAraci, 7, 7); lcd.update ();} yog (yer == 5) {lcd.drawBitmap (34, asama, dusmanAraci, 7, 7); lcd.update ();} yog (yer == 6) {lcd.drawBitmap (42, asama, dusmanAraci, 7, 7); lcd.update ();}}

tsis muaj dab tsi oyunbitti () {// yog tias peb ua tsis tiav, qhov kev ua si dhau

thaum (1) {ncua (100); // tos 1 lub hlis lcd.clrScr (); lcd.setFont (SmallFont); lcd.print ("OYUN BITTI", CENTER, 8); // luam game hla lcd.print ("skorunuz =", 3, 30); // luam koj cov qhab nia lcd.setFont (MediumNumbers); lcd.printNumI (skor, 60, 25); // tau qhab nia kawg lcd.update (); }}

void teeb tsa () {

pinMode (BL, NTAWV); // teeb tsa rov qab teeb Cov zis pinMode (xpin, INPUT); // teeb x tus pin raws li kev nkag lcdInitLCD (); // pib lub lcd screen lcd.setContrast (55); // teeb qhov sib txawv (amound 0 txog 127) Serial.begin (9600); // pib serial comunation}

void voj () {

analogWrite (BL, 350); oyunEkrani ();

// joyistic durumu … // teeb tsa qhov chaw joyistick …

int durumx = analogRead (xpin); if (durumx <300 && pozisyon! = 1 && kontrol == true) {// yog qhov chaw! = 1, x state600 && pozisyon! = 6 && kontrol == true) {// yog qhov chaw! = 3, x xeev> 600 thiab tswj yog qhov tseeb pozisyon ++; // nce qhov chaw nws txhais tau tias txav cov duab mus rau txoj cai kontrol = cuav; } lwm tus yog (durumx> 300 && durumx <600) {kontrol = tseeb; } // pozisyon durumu… // txoj haujlwm lub xeev… yog (pozisyon == 1) {// yog qhov chaw = 1; lcd.drawBitmap (2, 41, arac, 7, 7); lcd.update ();} // kos peb lub nkoj yog tias (pozisyon == 2) {lcd.drawBitmap (10, 41, arac, 7, 7); lcd.update ();} yog (pozisyon == 3) {lcd.drawBitmap (18, 41, arac, 7, 7); lcd.update ();} yog (pozisyon == 4) {lcd.drawBitmap (26, 41, arac, 7, 7); lcd.update ();} yog (pozisyon == 5) {lcd.drawBitmap (34, 41, arac, 7, 7); lcd.update ();} yog (pozisyon == 6) {lcd.drawBitmap (42, 41, arac, 7, 7); lcd.update ();}

yog (dusmanoldu) {// yog tias cov yeeb ncuab zoo li tuag lawm, xyuas seb lawv puas tuag

dusmankonum1 = pozisyon; // kos thawj tus yeeb ncuab zoo dusmankonum2 = random (0, 6); // kos lwm tus yeeb ncuab zoo ib yam dusmankonum3 = random (0, 6); dusmankonum4 = random (0, 6); dusmankonum5 = random (0, 6); dusmaninYdekonumu = 0; // coj yeeb ncuab los saum dusmanoldu = cuav;} // yeeb ncuab rov tsim dua kom lawv tsis tuag

dusmanAracidurum (dusmankonum1, dusmaninYdekonumu); dusmaninYdekonumu ++; // kos thawj tus yeeb ncuab zoo thiab tau txais nws los ntawm sab saum toj mus rau hauv qab

dusmanAracidurum (dusmankonum2, dusmaninYdekonumu); dusmaninYdekonumu ++; // kos tus yeeb ncuab thib ob zoo thiab tau txais nws los ntawm sab saum toj mus rau hauv qab dusmanAracidurum (dusmankonum3, dusmaninYdekonumu); dusmaninYdekonumu ++; dusmanAracidurum (dusmankonum4, dusmaninYdekonumu); dusmaninYdekonumu ++; yog (dusmaninYdekonumu> 35 && ((dusmankonum1 == pozisyon) || (dusmankonum2 == pozisyon) || (dusmankonum3 == pozisyon) || (dusmankonum4 == pozisyon))))); // qhov kev ua si dhau lawm}

yog (dusmaninYdekonumu> 42) {// yog tias peb lub cev khiav tawm ntawm cov yeeb ncuab

dusmanoldu = tseeb; // tua yeeb ncuab duab skor ++; // nce ib los ntawm ib tus qhab nia}

// skora gore hizi artiriyoruz // nce nrawm raws li tus qhab nia

yog (skor> = 0 && skor = 10 && skor = 20 && skor = 30 && skor = 40 && skor = 50) {hiz = 6; ncua (5); }

}

Kauj ruam 4: CODE BITMAP

Ntxiv mus, koj yuav tsum suav nrog cov duab bitmap rau cov duab nws yuav tsum yog.c cov ntaub ntawv.

#suav nrog // suav nrog rau txoj haujlwm ua haujlwm

const unsigned char arac PROGMEM = {// peb cov duab bitmap

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};

const unsigned char dusmanAraci PROGMEM = {// yeeb ncuab nkoj bitmap

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};

Kauj Ruam 5: Ua Tsaug Rau Saib

Lub ntsiab lus ntawm qee cov lus:

Yog => Game

Arac => Cov duab

Dusman => Yeeb ncuab

kontrol => tswj

Konum, Yer => Qhov chaw

Oyun Bitti => Game Over

Skor => Cov qhab nia

Hiz => Ceev

Pom zoo: